/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-22 11:17:43
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-22 13:20:47
 */
import 'package:flutter_data_center/model/common/menu_model.dart';
import 'package:flutter_data_center/model/visitor/visitor_model.dart';
import 'package:flutter_data_center/net/dio_utils.dart';
import 'package:get/get.dart';

class VisitorController extends GetxController {
  // 总人数
  int _total = 0;
  int get total => _total;

  // 访客列表
  List<Visitor> _list;
  List<Visitor> get list => _list;
  void getVisitor() async {
    _list = [];
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.visitorList,
    );
    if (responseInfo.success) {
      var data = responseInfo.data;
      _total = data["total"];
      for (var item in data['visitor']) {
        _list.add(Visitor.fromJson(item));
      }

      update();
    }
  }

  // 创建一个map
  Map<String, String> _staus = {
    "in": "在校",
    "out": "离校",
  };
  Map<String, String> get status => _staus;

  // 获取当前选择的列表
  Function get currentlist => () {
        List<Visitor> currentlist =
            _list.where((v) => v.status == _visitorType).toList();
        return currentlist;
      };
  String _visitorType = "in";
  String get visitorType => _visitorType;

  void changeType(String type) {
    _visitorType = type;
    currentlist();
    update();
  }

  // 菜单
  List<MenuModel> _menus = [MenuModel("在校", "in"), MenuModel("离校", "out")];
  List<MenuModel> get menus => _menus;
}
